<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Groups/classes/PhpFox_ComponentGroupInviteBlock.class.php, $Author:  $ */



/** Component for approving pictures in gallery
 * @version $Id: PhpFox_ComponentCategories.class.php
 *  Max Kovrigovich
 * @package module.groups
 */
class PhpFox_Mod_Groups_ComponentGroupInviteBlock extends BaseComponent
{
    /** Processing method
     */
    function process()
    {
        //check permissions
        $oSecurityService = App::getModuleService('Account', 'Security');
		/* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
		$oSecurityService->checkPerm('groups', array('read_only', 'full'));

        $oGroupsService = $this->_oModule->getService('Groups');
        /* @var $oGroupsService PhpFox_Mod_Groups_ServiceGroups */

        $oReq = &App::getRequest();
        /* @var $oReq Request */

        $oTpl = $this->_oModule->getTemplate();

        $iGroupId = $oReq->getInt('id', 0);
        if(!$iGroupId)
        {
            return '';
		}

		$oUser = $this->getParam('user');
		if ( $oGroupsService->isMember($iGroupId, App::getUser('user')) )
		{
			return '';
		}

        $aInviteData = $oGroupsService->getInviteData($iGroupId, App::getUser('user'));

        $sInviteAction = $oReq->get('group_invite_on','no');
        if(count($aInviteData) && $sInviteAction == 'ok')
        {
            //check fields
            if(
            $aInviteData['invite'] == $oReq->get('group_invite_user','0')
            &&
            $aInviteData['type_id'] == $oReq->get('type_id','0')
            &&
            $aInviteData['id'] == $oReq->get('invite_id','0')
            &&
            $aInviteData['group_id'] == $oReq->get('id','0')
            &&
            !$oGroupsService->isMember($iGroupId, App::getUser('user'))
            )
            {
                if($oReq->get('accept'))
                {
                    $oGroupsService->addGroupMember($iGroupId, App::getUser('user'), $aInviteData['type_id'], $aInviteData['id']);
				}
                
				if($oReq->get('deny'))
                {
                    $oGroupsService->removeInvite($aInviteData['id']);
				}
				
				App::gotoUrl('public.groups.view', array('id' => $aInviteData['group_id']));
               	exit;
            }
        }

        $sHtml = '';
        if(count($aInviteData))
        {
	        $oTpl->assign(array(
	            'aInviteData'     => $aInviteData,
	        ));
	        $sHtml = $oTpl->fetch('GroupInviteBlock.html');
        }
        return $sHtml;
    }
}
?>